/*
 * Copyright 2017 Baiyyy
 * @(#)NettyServerDemo.java
 */

package com.byyy.ccts.modules.cc.server;

import com.byyy.ccts.core.base.ILogBase;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Netty服务器
 * Created by DELL on 2018-4-26.
 */
@Service("cctsServer")
public class CCTSServer implements ILogBase {

    @Autowired
    private CCTSServerInitializer cctsServerInitializer;

    public void bind() {
//        //用于服务器端接受客户端的连接
//        EventLoopGroup bossGruop = new NioEventLoopGroup();
//        //用于网络事件的处理
//        EventLoopGroup workGroup = new NioEventLoopGroup();
//        try {
//            ServerBootstrap b = new ServerBootstrap();
//            b.group(bossGruop, workGroup).channel(NioServerSocketChannel.class)
//                    .childHandler(cctsServerInitializer).option(ChannelOption.SO_BACKLOG, 1024);
//            //指定此套接口排队的最大连接个数
//            ChannelFuture f = b.bind(8686).sync();
//            // 接下来这句话会造成阻塞
//            f.channel().closeFuture().sync();
//        }
//        catch (Exception e) {
//            logger.error(e.getMessage(), e);
//        }
//        finally {
//            bossGruop.shutdownGracefully();
//            workGroup.shutdownGracefully();
//        }
    }

}
